package com.ruyuan.eshop.seller.controller.seller.aftersale;

import com.ruyuan.eshop.framework.context.user.UserContext;
import com.ruyuan.eshop.framework.core.WebPage;
import com.ruyuan.eshop.common.domain.dto.RefundQueryParam;
import com.ruyuan.eshop.common.domain.vo.RefundRecordVO;
import com.ruyuan.eshop.common.service.aftersale.AfterSaleRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 售后退款相关API
 * @author pwd
 * @version 1.0
 */
@Api(description="售后退款相关API")
@RestController
@RequestMapping("/api/v1.0/after-sales/refund")
@Validated
public class RefundSellerController {

    @Autowired
    private AfterSaleRefundService afterSaleRefundService;

    /**
     * 获取售后退款单列表
     * @param param
     * @return
     */
    @ApiOperation(value = "获取售后退款单列表", response = RefundRecordVO.class)
    @GetMapping
    public WebPage list(@Valid RefundQueryParam param) {
        param.setSellerId(UserContext.getSeller().getSellerId());
        return afterSaleRefundService.list(param);
    }

    /**
     * 在线支付订单商家退款
     * @param serviceSn
     */
    @ApiOperation(value = "在线支付订单商家退款")
    @PostMapping(value = "/{service_sn}")
    public void refund(@PathVariable("service_sn") String serviceSn) {
        this.afterSaleRefundService.sellerRefund(serviceSn);
    }
}
